package com.ykt.service;

import com.ykt.common.utils.UB;
import com.ykt.model.MediaSource;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 多媒体资源
 * @author long.hua
 * @version 1.0.0
 * @since 2016-05-24 23:36
 */
public class MediaSourceService {

    private MediaSource mediaSourceDao = MediaSource.dao;


    // 查询指定业务对象的多媒体资源
    public List<MediaSource> find(MediaSource.BizType bizType, int bizId){
        return mediaSourceDao.find(bizType, bizId);
    }


    // 查询指定一批业务对象的多媒体资源，以业务类型+业务ID为key，媒体资源为Val的值
    public Map<String, List<MediaSource>> find(MediaSource.BizType bizType, List<Integer> bizIds){
        List<MediaSource> mediaSources = mediaSourceDao.find(bizType, bizIds);
        if(mediaSources == null){
            return null;
        }

        Map<String, List<MediaSource>> mediaSourceMap = new HashMap<>();

        for (MediaSource mediaSource : mediaSources) {
            if(mediaSource.get(MediaSource.biz_type) != null && UB.i(mediaSource.get(MediaSource.biz_id)) > 0){

                String key = mediaSource.getStr(MediaSource.biz_type) + mediaSource.get(MediaSource.biz_id);
                if(!mediaSourceMap.containsKey(key)){

                    mediaSourceMap.put(key, new ArrayList<MediaSource>());
                }
                mediaSourceMap.get(key).add(mediaSource);
            }
        }

        return mediaSourceMap;
    }

}
